//app.js
App({
    onLaunch: function (options) {
        var up_user = options.query.id
        this.lih_login(up_user)
        
    },
    globalData: {
        //appurl: "http://192.168.2.135/"
        appurl: "https://zhengshangche.sankoumu.com/"
        // appurl: "http://192.168.2.209:8090"
    },
    lih_login:function(up_user){
        const that = this
        wx.login({
            success(res) {
                let code = res.code
                wx.request({
                    url: that.globalData.appurl + 'api/wechat/mp_auth', //登录接口
                    data: {
                        code: code,
                        up_user: up_user
                    },
                    method: "POST",
                    header: {
                        'content-type': 'application/x-www-form-urlencoded' // 默认值
                    },
                    success(res) {
                        if (res.data.statusCode === 200) {
                            wx.setStorage({
                                key: "token",
                                data: res.data.data.token,
                            })
                            wx.setStorage({
                                data: res.data.data.cache_key,
                                key: 'cache_key',
                            })
                            wx.showToast({
                                title: "登录成功",
                                icon: "none",
                            })
                            
                        }else{
                            that.lih_login()
                        }
                        
                    }
                })

            },
            fail(res) {
                wx.showToast({
                    title: "登录失败",
                    icon: "none",
                })
            }
        })
    },
    get_user_location:function(){
        wx.openSetting()
    }
})